package com.sghd.fight.module.game.event;

import com.sghd.common.event.AbstractReceiver;
import com.sghd.fight.module.game.service.GameService;
import com.sghd.fight.module.game.service.ThreadService;
import com.sghd.fight.module.game.service.work.RoomRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ExitEventReceiver extends AbstractReceiver<ExitEvent> {
    @Autowired
    private GameService gameService;
    @Autowired
    private ThreadService threadService;

    @Override
    public void doEvent(final ExitEvent event) {
        threadService.submitMatch(new RoomRunner() {
            @Override
            public void run(Date now) {
                for (Long playerId : event.getPlayerIds()) {
                    gameService.exit(playerId);
                }
            }
        });

    }

    @Override
    public String[] getEventNames() {
        return new String[]{ExitEvent.NAME};
    }

}
